package com.scau.service;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.scau.dao.BaseDAO;
import com.scau.exception.DataAccessException;

@Component
public class BaseService<T>{

	private BaseDAO<T> baseDAO;
	
	@Transactional
	public void add(T entity) throws DataAccessException{
		baseDAO.add(entity);
	}
	
	@Transactional
	public void delete(T entity) throws DataAccessException{
		baseDAO.delete(entity);
		
	}
	
	@Transactional
	public void update(T entity) throws DataAccessException {
		baseDAO.update(entity);
	}
	
	@Transactional
	public List<T> findByExample(T entity) throws DataAccessException {
		
		return baseDAO.findByExample(entity);
	}
	
	@Transactional
	public List<T> listAll(T entity) throws DataAccessException {
		return baseDAO.listAll(entity);
	}
	@Transactional
	public List<T> find(T entity, Map<String, Object> map, final int start,
			final int size, final String descPropertyName,
			final String ascPropertyName) throws DataAccessException {
		return baseDAO.find(entity, map, start, size, descPropertyName, ascPropertyName);
	}
	@Transactional
	public List<T> list(T entity, Map<String, Object> map,final int start,final int size,String descPropertyName,String ascPropertyName)throws DataAccessException  {
		return baseDAO.list(entity, map, start, size, descPropertyName,ascPropertyName);
	}
	
	@Transactional
	public List<T> findByCondition(String sql){
		return baseDAO.findByCondition(sql);
	}
		
	@Transactional
	public T findUniqueById(T entity, String name,String value, final String descPropertyName) throws DataAccessException {
		return baseDAO.findUniqueById(entity, name, value, descPropertyName);
	}
//	***************************************************

	public BaseDAO<T> getBaseDAO() {
		return baseDAO;
	}

	@Resource
	public void setBaseDAO(BaseDAO<T> baseDAO) {
		this.baseDAO = baseDAO;
	}
}
